package za.ac.wits.elen7045.persistence.dao;

import za.ac.wits.elen7045.persistence.Environment;
import za.ac.wits.elen7045.persistence.PersistentObject;
import za.ac.wits.elen7045.persistence.model.Account;
import za.ac.wits.elen7045.persistence.model.ServiceProvider;
import za.ac.wits.elen7045.persistence.model.Statement;
import za.ac.wits.elen7045.persistence.model.User;

public abstract class DaoFactory {
	
	private static final Environment DEFAULT_ENVIRONMENT = Environment.PRODUCTION;

	public static <T extends PersistentObject> Dao getDao(Class<T> clazz) {
		// TODO: determine DAO type to retrieve...
		return getSqlDao(clazz, DEFAULT_ENVIRONMENT);
	}
	
	public static <T extends PersistentObject> SqlDao getSqlDao(Class<T> clazz) {
		return getSqlDao(clazz, DEFAULT_ENVIRONMENT);
	}
	
	public static <T extends PersistentObject> SqlDao getSqlDao(Class<T> clazz, Environment env) {
		if (clazz == User.class) {
			return new SqlUserDAO(env);
		} 
		else if (clazz == Account.class) {
			return new SqlAccountDAO(env);
		} 
		else if (clazz == ServiceProvider.class) {
			return new SqlServiceProviderDAO(env);
		} 
		else if (clazz == Statement.class) {
			return new SqlStatementDAO(env);
		}
		return null;
	}
	
	/* Users */
	
	public static SqlUserDAO getSqlUserDAO() {
		return getUserDAO(DEFAULT_ENVIRONMENT);
	}
	public static SqlUserDAO getUserDAO(Environment env) {
		return new SqlUserDAO(env);
	}
	
	/* Service Providers */
	
	public static SqlServiceProviderDAO getSqlServiceProviderDAO() {
		return getServiceProviderDAO(DEFAULT_ENVIRONMENT);
	}
	public static SqlServiceProviderDAO getServiceProviderDAO(Environment env) {
		return new SqlServiceProviderDAO(env);
	}
	
	/* Accounts */
	
	public static SqlAccountDAO getSqlAccountDAO() {
		return getAccountDAO(DEFAULT_ENVIRONMENT);
	}
	public static SqlAccountDAO getAccountDAO(Environment env) {
		return new SqlAccountDAO(env);
	}

	/* Statements */
	
	public static SqlStatementDAO getSqlStatementDAO() {
		return getStatementDAO(DEFAULT_ENVIRONMENT);
	}
	public static SqlStatementDAO getStatementDAO(Environment env) {
		return new SqlStatementDAO(env);
	}
	
}
